#ifndef SHENLAN_VERTEX_ANIMATION_TEXTURE
#define SHENLAN_VERTEX_ANIMATION_TEXTURE

//LDR
float2 GetFrameUV(float2 uvIndex_, float frame_, float frameCount_, float3 boundMin_, float3 boundMax_)
{
    //activePixelRatorXY
    float tempAprX = boundMin_.b * 10;
    float activePixelsRatioX = 1 - ceil(tempAprX) + tempAprX;
    float tempAprY = boundMax_.r * -10;
    float activePixelsRatioY = 1 - tempAprY + floor(tempAprY);

    float timeFactor = ((frame_) % frameCount_) / frameCount_;

    float2 frameUV = 0;
    frameUV.x = uvIndex_.x * activePixelsRatioX;
    frameUV.y = 1 - (1 - uvIndex_.y + timeFactor) * activePixelsRatioY;
    return frameUV;
}

//LDR
float2 GetLookupUV(float4 lutData_, float3 boundMin_)
{
    float temp = boundMin_.r * -10;
    float byte = lerp(255, 2048, step(0.5, temp - floor(temp)));

    float2 lutUV = 0;
    lutUV.x = lutData_.r + lutData_.g / byte;
    lutUV.y = 1 - lutData_.b - lutData_.a / byte;
    return lutUV;
}

//LDR
float3 GetNormal(float4 normalMap_)
{
    float4 data = normalMap_ = normalMap_ * 2 - 1;
    float3 M1 = float3(0, 1, 0);
    float3 M2 = M1 * data.w + cross(data.xyz, M1);
    return normalize(cross(data.xyz, M2) * 2 + M1);
}

float3 GetPosData(float3 posMap_,float3 boundMin_,float3 boundMax_)
{    
    return posMap_.xyz * (boundMax_ - boundMin_) + boundMin_;
}

float3 GetFinalPosOS(float2 uvIndex_,float3 posData_,float3 posOS_)
{
    #if defined(_VAT_REMESH)
        return lerp(posData_, 0, step(-0.1, -uvIndex_.y));
    #else
        return posOS_ + posData_;
    #endif
}

#endif